package com.demo.core.service;

import io.quarkus.scheduler.Scheduler;
import io.quarkus.scheduler.Trigger;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.RequiredArgsConstructor;

import java.util.List;

@ApplicationScoped
@RequiredArgsConstructor
public class JobService {

    private final Scheduler scheduler;

    public void addJob() {
        scheduler.newJob("newJob")
                .setCron("0 0/3 * * * ?")
                .setTask(executionContext ->{
                    System.out.println("每3分钟执行一次任务");
                })
                .schedule();
    }

    public void removeMyJob() {
        scheduler.unscheduleJob("newJob");
    }

    public List<Trigger> jobs(){
        return scheduler.getScheduledJobs();
    }

    public Trigger getTrigger(String jobName){
        return scheduler.getScheduledJob(jobName);
    }

    public boolean stopAll(){
        scheduler.pause();
        return Boolean.TRUE;
    }

    public boolean stop(String jobName){
        scheduler.pause(jobName);
        return Boolean.TRUE;
    }
    public boolean resumeAll(){
        scheduler.resume();
        return Boolean.TRUE;
    }
    //恢复
    public boolean resume(String jobName){
        scheduler.resume(jobName);
        return Boolean.TRUE;
    }


}
